﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VoteServices.VoteClass;

namespace VoteServices
{
    /// <summary>
    /// 投票记录服务
    /// </summary>
    public class RecordService
    {
        /// <summary>
        /// 获取投票记录
        /// </summary>
        /// <param name="OptionId"></param>
        /// <returns>Record List</returns>
        public List<Record> GetRecord(int OptionId)
        {
            return VoteData.records.Where(o=>o.OptionId==OptionId).ToList();
        
        }
        /// <summary>
        /// 检测当前用户是否投过票
        /// </summary>
        /// <param name="OptionId"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Boolean examine(int ProblemId, User user)
        {
            ProblemService voteServices = new ProblemService();
            Boolean b = false;
            if(VoteData.records==null)
            {
                return b;
            }
            List<Option> RecordOption = voteServices.GetOptions(ProblemId);
            List<Record> RecordUser = new List<Record>();
            for (int n = 0; n < RecordOption.Count; n++)
            {
                RecordUser.AddRange(VoteData.records.Where(o => o.OptionId == RecordOption[n].Id).ToList());
            }
            
            for(int count = 0; count < RecordUser.Count; count++)
            {
                if (RecordUser[count].VoteUser.Equals(user))
                    return true;
            }
            return b;
        }
        
    }
}
